import grails.test.*
import java.util.Date

class EmployeeTests extends GrailsUnitTestCase {
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testEmployeeInstanziation() {
        Employee emp = new Employee(firstName: "Johan", lastName: "Johansson", street: "Vasavägen",
                                    city: "Linköping", zipCode: 55555, dob: new Date(1972,07,22), 
                                    email: "johan.johansson@gmail.com",  title: "Mr",  salary: 10000.0, employeeId: 32,)

        assertEquals emp.firstName, "Johan"
        assertEquals emp.lastName, "Johansson"
        assertEquals emp.street, "Vasavägen"
        assertEquals emp.city, "Linköping"
        assertEquals emp.zipCode, 55555
        assertEquals emp.dob, new Date(1972,07,22)
        assertEquals emp.email, "johan.johansson@gmail.com"
        assertEquals emp.title, "Mr"
        assertEquals emp.employeeId, 32
    }

    void testGetWorkingHoursPerYear()
    {
         Employee emp1 = new Employee(firstName: "Johan", lastName: "Johansson", street: "Vasavägen",
                                    city: "Linköping", zipCode: 55555, dob: new Date(1982,07,22),
                                    email: "johan.johansson@gmail.com",  title: "Mr",  salary: 10000.0, percentageWork: 100.0, employeeId: 33,)

         Employee emp2 = new Employee(firstName: "Lars", lastName: "Larsson", street: "Vasavägen",
                                    city: "Linköping", zipCode: 55551, dob: new Date(1910,07,22),
                                    email: "lars.larsson@gmail.com",  title: "Mr",  salary: 10000.0, percentageWork: 100.0, employeeId: 34,)
        
        assertEquals emp1.getWorkingHoursPerYear(), 1732
        assertEquals emp2.getWorkingHoursPerYear(), 1700
        
    }

    void testEmployeeToString()
    {
         Employee emp3 = new Employee(firstName: "Lars", lastName: "Larsson", street: "Vasavägen",
                                    city: "Linköping", zipCode: 55551, dob: new Date(1932,07,22),
                                    email: "lars.larsson@gmail.com",  title: "Mr",  salary: 10000.0, employeeId: 35)

        assertEquals emp3.toString(), "Lars Larsson "

    }

    void testIsWorkingOverTime(){

        Employee emp = new Employee(firstName: "Karl", lastName: "Karlsson", street: "Stångebro",
                                    city: "Linköping", zipCode: 55331, dob: new Date(1962,07,22),
                                    email: "karl.karlsson@gmail.com",  title: "Mr",  salary: 10000.0, percentageWork: 90.0,  employeeId: 36)

        Employee emp1 = new Employee(firstName: "Kalle", lastName: "Kallesson", street: "Stångebro",
                                    city: "Linköping", zipCode: 55431, dob: new Date(1962,07,24),
                                    email: "kalle.kallesson@gmail.com",  title: "Mr",  salary: 10000.0, percentageWork: 110.0,  employeeId: 37)
                                
        assertFalse emp.isWorkingOverTime()
        assertFalse emp1.isWorkingOverTime()
        
    }

    void testHoursWork(){
         Employee emp = new Employee(firstName: "Karl", lastName: "Karlsson", street: "Stångebro",
                                    city: "Linköping", zipCode: 55331, dob: new Date(1962,07,22),
                                    email: "karl.karlsson@gmail.com",  title: "Mr",  salary: 10000.0, percentageWork: 90.0,  employeeId: 36)

        assertEquals emp.hoursWork(), 1377

    }

    void testpercentageNotAssigned(){
        Employee emp = new Employee(firstName: "Karl", lastName: "Karlsson", street: "Stångebro",
                                    city: "Linköping", zipCode: 55331, dob: new Date(1962,07,22),
                                    email: "karl.karlsson@gmail.com",  title: "Mr",  salary: 10000.0, percentageWork: 90.0,  employeeId: 36)


        assertEquals emp.percentageNotAssigned(), 90
    }

    void testhoursNotAssigned(){
        Employee emp = new Employee(firstName: "Karl", lastName: "Karlsson", street: "Stångebro",
                                    city: "Linköping", zipCode: 55331, dob: new Date(1962,07,22),
                                    email: "karl.karlsson@gmail.com",  title: "Mr",  salary: 10000.0, percentageWork: 90.0,  employeeId: 36)

        assertEquals emp.hoursNotAssigned(), 1530

    }

    void testactualWorkingPercentagePerYear(){
         Employee emp = new Employee(firstName: "Karl", lastName: "Karlsson", street: "Stångebro",
                                    city: "Linköping", zipCode: 55331, dob: new Date(1962,07,22),
                                    email: "karl.karlsson@gmail.com",  title: "Mr",  salary: 10000.0, percentageWork: 90.0,  employeeId: 36)

        assertEquals emp.actualWorkingPercentagePerYear(), 0
    }

}
